package org.stimuliband.dsp.dft;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class Main {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FileSystem fs = FileSystems.getDefault();
        Path file = fs.getPath(System.getProperty("user.dir"), "out_dtmf4.raw");
        FileChannel channel = FileChannel.open(file, StandardOpenOption.READ);
        System.out.println("channel.size(): " + channel.size());
        //ByteBuffer buffer = ByteBuffer.allocate((int) channel.size() / 10);
        ByteBuffer buffer = ByteBuffer.allocate(8000);
        channel.read(buffer);
        buffer.rewind();
        System.out.println("buffer.remaining(): " + buffer.remaining());

        int signal[] = new int[buffer.remaining()];
        for (int i = 0; i < signal.length; i++) {
            signal[i] = buffer.get() & 0xFF;
        }

        DFT dft = new DFT(signal);
        dft.compute();
    }
}
